package main

import (
	"encoding/json"
	"io/ioutil"
	"log"
)

var (
	gConf = &Config{}
)

type JiraConf struct {
	User        string `json:"user"`
	Passwd      string `json:"passwd"`
	Endpoint    string `json:"endpoint"`
	BoardName   string `json:"board-name"`
	ProjectName string `json:"project-name"`
	ProjectKey  string `json:"project-key"`
	SprintName  string `json:"sprint-name"`
	SprintID    int    `json:"sprint-id"`
}

type Config struct {
	Jira  JiraConf            `json:"jira"`
	En2Ch map[string]string   `json:"en2ch"`
	Team  map[string][]string `json:"team"`
}

func LoadConfig(path string) {
	d, err := ioutil.ReadFile(path)
	if err != nil {
		log.Fatal("read file", path, err)
	}
	err = json.Unmarshal(d, &gConf)
	if err != nil {
		log.Fatal("unmarshall", err)
	}
}

func getRealName(str string) string {
	name, ok := gConf.En2Ch[str]
	if ok {
		return name
	}
	return str
}
